package com.dx.login;

import java.util.Date;

import com.dx.login.User;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;

public class RegistController  extends Controller{
	public void index() {
		render("/WEB-INF/jsp/login/regist.jsp");
	}
	
	public void regSuccess() {
		render("/WEB-INF/jsp/login/loginSuccess.jsp");
	}
	
	@Before(RegistValidator.class)
	public void reg() {
		System.out.println(">>>"+this.getModel(User.class));
		System.out.println("user.password:"+this.getPara("user.password"));
		
		User user=new User();
		if("email".equals(this.getPara("registType"))){
			user.set("account", this.getPara("emailEmail"));
			user.set("password", this.getPara("emailPassword"));
			user.set("email", this.getPara("emailEmail"));
					
		}else{
			user.set("account", this.getPara("telTel"));
			user.set("tel", this.getPara("telTel"));
			user.set("password", this.getPara("telPassword"));
			user.set("email", this.getPara("telEmail"));
		}
		user.set("create_time", new Date());
		System.out.println(User.dao.findById(user.get("account")));
		if(User.dao.findById(user.get("account"))==null)
			user.save();
		this.getSession().setAttribute("user", user);

		//render("/WEB-INF/jsp/login/regist.jsp");
		//forwardAction("/");
		redirect("/");
	}
}
